package cc.iteachyou.template.tools;


import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author duanbowei123
 * @Date:2023/7/6
 * @Description:
 * @version：1.0
 **/
public class CalendarUtil {

    /**
     * 获取Calendar对象
     *
     * @return
     */
    public static Calendar calendar() {
        return Calendar.getInstance();
    }

    /**
     * Date 转 Calendar
     *
     * @param date
     * @return
     */
    public static Calendar calendar(Date date) {
        if (date == null) {
            return null;
        }
        return calendar(date.getTime());

    }

    /**
     * 根据时间戳 和 默认时区生成 Calendar
     *
     * @param millis
     * @return
     */
    public static Calendar calendar(long millis) {
        return calendar(millis, TimeZone.getDefault());
    }

    /**
     * 指定时间戳和时区生成Calendar
     *
     * @param millis
     * @param timeZone
     * @return
     */
    public static Calendar calendar(long millis, TimeZone timeZone) {
        final Calendar cal = Calendar.getInstance(timeZone);
        cal.setTimeInMillis(millis);
        return cal;
    }

    /**
     * 判断当前时间是否是上午
     *
     * @param calendar
     * @return
     */
    public static boolean isAM(Calendar calendar) {
        return Calendar.AM == calendar.get(Calendar.AM_PM);
    }

    /**
     * 判断当前时间是否是下午
     *
     * @param calendar
     * @return
     */
    public static boolean isPM(Calendar calendar) {
        return Calendar.PM == calendar.get(Calendar.AM_PM);
    }


}
